#include <iostream>
using namespace std;

class Singleton{
public:
    static Singleton * getinstance(){
        if(_ps==nullptr){
            _ps=new Singleton();
        }
        return _ps;
    }
    void print(void){
        cout<<"Singleton::print()"<<endl;
    }
    static  void destroy(void){
        if(_ps){
            delete _ps;
            _ps=nullptr;
        }
    }
    Singleton(const Singleton& rhs)=delete;
    Singleton & operator=(const Singleton& rhs)=delete;
private:
    Singleton(){
        cout<<"Singleton"<<endl;
    }
    static Singleton * _ps;  
};
Singleton * Singleton:: _ps=nullptr;

void test(){
    Singleton *ps1=Singleton::getinstance();
    Singleton *ps2=Singleton::getinstance();
    Singleton::destroy();
    Singleton *ps3=Singleton::getinstance(); 
}

int main(int argc, char * argv[]){
    test();
    return 0;
}

